﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Student
    {
        private Model.ThesisDB db = new Model.ThesisDB();

        /// <summary>
        /// 根据学生姓名及密码查找该学生对应的ID号
        /// </summary>
        /// <param name="name">学生姓名</param>
        /// <param name="password">学生密码</param>
        /// <returns></returns>
        public Guid Check(string name, string password)
        {
            Guid guid = (from u in db.Student
                         where u.sName == name && u.sPassword == password
                         select u.ID).FirstOrDefault();
            return guid;
        }

        /// <summary>
        /// 根据学生姓名及密码查找该学生对应的ID号
        /// </summary>
        /// <param name="name">学生姓名</param>
        /// <param name="password">学生密码</param>
        /// <returns></returns>
        public Guid Get(string name, string password)
        {
            Guid guid = (from u in db.Student
                         where u.sName == name && u.sPassword == password
                         select u.ID).FirstOrDefault();
            return guid;
        }

        /// <summary>
        /// 将学生实体写入到数据库中
        /// </summary>
        /// <param name="student">学生实体</param>
        public void Add(Model.Student student)
        {
            db.Student.InsertOnSubmit(student);
            db.SubmitChanges();
        }
        /// <summary>
        /// 根据指定学生ID号查找对应教师ID号
        /// </summary>
        /// <param name="guid">学生ID号</param>
        /// <returns></returns>
        public Guid SearchByTeacherID(Guid guid)
        {
            Guid id = new Guid((from s in db.Student
                                where s.ID == guid
                                select s.TeacherID).First().ToString());
            return id;
        }
    }
}
